import {
    createRouter,
    createWebHashHistory
} from "vue-router"
import store from '@/store'

const login = () => import("@/pages/ucenter/login.vue")
const _404 = () => import("@/pages/pageList/404.vue")

const routes = [
    {
        path: "/",
        name: "home",
        redirect: "/home"
    },
    {
        path: "/login",
        name: "login",
        component: login
    },
    {
        path: "/404",
        name: "404",
        component: _404
    },
    {
        name: 'NotFound',
        path: '/:patchMatch(.*)*',
        component: _404
    }
]

const router = createRouter({
    history: createWebHashHistory(),
    routes,
});

router.beforeEach((to, from) => {
    let token = store.getters['user/getToken'];
    if (to.path != '/login' && !token) {
        return "/login";
    }
})
export default router